#include <vector>
#include <iostream>

using namespace std;

class Solution {
public:
    int m, n;

    // 时间复杂度为 O(mn)
    void solve(vector<vector<char>>& board) {
        m = board.size();
        n = board[0].size();

        for (int i = 0; i < n; i++) {
            dfs(board, 0, i);
        }

        if (m - 1 > 0) {
            for (int i = 0; i < n; i++) {
                dfs(board, m - 1, i);
            }
        }

        for (int i = 0; i < m; i++) {
            dfs(board, i, 0);
        }

        if (n - 1 > 0) {
            for (int i = 0; i < m; i++) {
                dfs(board, i, n - 1);
            }
        }

        // 将标记为 Y 的还原，并且将 O 的标记为 X
        for (int x = 0; x < m; x++) {
            for (int y = 0; y < n; y++) {
                if (board[x][y] == 'Y') {
                    board[x][y] = 'O';
                } else if (board[x][y] == 'O') {
                    board[x][y] = 'X';
                }
            }
        }
    }

    // 从边缘进行深搜，然后标记为 Y
    void dfs(vector<vector<char>>& board, int x, int y) {
        if (board[x][y] == 'X' || board[x][y] == 'Y') {
            return;
        }

        board[x][y] = 'Y';

        if (x > 0) {
            dfs(board, x - 1, y);
        }

        if (y < n - 1) {
            dfs(board, x, y + 1);
        }

        if (x < m - 1) {
            dfs(board, x + 1, y);
        }

        if (y > 0) {
            dfs(board, x, y - 1);
        }
    }
};

int main() {
    vector<vector<char>> board = {{'X','X','X','X'},{'X','O','O','X'},{'X','X','O','X'},{'X','O','X','X'}};

    Solution().solve(board);

    for (int i = 0; i < board.size(); i++) {
        for (int j = 0; j < board[i].size() - 1; j++) {
            cout << board[i][j] << ", ";
        }
        cout << board[i][board[i].size() - 1] << endl;
    }

    return 0;
}